/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Máté
 */

// kapu ősosztály
public abstract class Gate extends Element implements IComposite {

    private Wire output;
    private List<Wire> inputs;
    // stabilitásvizsgálathoz használt segédváltozó
    private Boolean dejavu;

    public Gate(Integer legCount) {
        super(legCount);
        this.output = new Wire();
        this.inputs = new ArrayList<Wire>();
        this.dejavu = false;
        ResetHandler.addWire(this.output);
    }

    public Wire getOutput() {
        return this.output;
    }

    public List<Wire> getInputs() {
        return this.inputs;
    }

    public boolean isDejavu() {
        return this.dejavu;
    }

    public void setDejavu(boolean dejavu) {
        this.dejavu = dejavu;
    }

    public void addOutput(Display display) {
        this.output.setDisplay(display);
    }

    public void addOutput(Oscilloscope oscilloscope) {
        this.output.setOscilloscope(oscilloscope);
    }

    public void addOutput(Gate gate) throws Exception {

        if (gate instanceof Port && this instanceof Port) {
            if (((Port) gate).isOutput()) {
                throw new Exception("Error: Cannot connect two outputs!");
            }
        }

        this.output.addGate(gate);
        gate.getInputs().add(this.output);
    }

    // kapu metódusa
    public abstract void gateFunc();
}
